home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 049b.dms / 049b.adf / MORE_SOURCE_CODE / Squash.AMOS / Squash.amosSourceCode
AMOS Source Code  |  1992-02-26  |  3KB  |  90 lines

  1. '===================================================================== 
  2. ' Compression tutorial, By A. Smith for Amoszine 
  3.  
  4. ' "Compressing without PowerPacker"
  5. '===================================================================== 
  6.  
  7.  
  8. ' Open lowres screen to hold our image 
  9.  
  10. Screen Open 0,320,256,32,Lowres
  11. Flash Off : Curs Off 
  12.  
  13. ' Open screen for messages 
  14.  
  15. Screen Open 1,320,30,2,Lowres
  16. Screen Display 1,,150,,
  17. Flash Off : Curs Off 
  18.  
  19. ' Load the IFF image 
  20.  
  21. Screen 0
  22. Load Iff Fsel$("","","Please select an IFF picture","")
  23. Wait Vbl 
  24.  
  25. ' Pack as screen into bank 15 (what a poet!) 
  26.  
  27. Screen 1 : Print "Packing picture into bank 15" : Screen 0
  28. Spack 0 To 15
  29.  
  30. ' Save memory bank to disk 
  31.  
  32. Screen 1 : Print "Size of packed image ";Length(15) : Screen 0
  33. Save Fsel$("","","Give filename for ABK image","Ensure it ends in .ABK"),15
  34.  
  35. ' Squash the memory bank.  Note that the function - Start - will return
  36. ' the start address of memory bank 15 and 'length' will return the length
  37. ' of the bank in bytes.  The next '1' flag tells the squasher to use FAST
  38. ' compression.  The 4095 will give the best compression.  The 0 is the 
  39. ' colour to flash when it is crunching.  The value that is returned in L 
  40. ' is the length of the squashed data.
  41.  
  42. Screen 1 : Print "Squashing memory bank" : Screen 0
  43. Cls 
  44. L= Extension_5_00CE(Start(15),Length(15),1,4095,0)
  45.  
  46. ' Bsave will save out the memory bank without the bank header information. 
  47. ' In other words, it is just saving the bytes that were created by using 
  48. ' the Squash function.   
  49.  
  50. Screen 1 : Print "Size of squashed data : ";L : Screen 0
  51. F$=Fsel$("","","Give filename for squashed data","Ensure it ends in .CMP")
  52. Bsave F$,Start(15) To Start(15)+L
  53. Erase 15
  54.  
  55. ' Reopen the file I saved out so the length of the file can be returned. 
  56.  
  57. Open In 1,F$
  58.  
  59. ' Get length of file and store in SIZEOFFILE 
  60.  
  61. SIZEOFFILE=Lof(1)
  62. Close 1
  63.  
  64. ' Reserve bank 15 as temporary workspace (using Fast mem), twice the 
  65. ' size of the file.  This is so that the decompressed data will fit
  66. ' into the memory bank.
  67.  
  68. Reserve As Work 15,SIZEOFFILE*2
  69.  
  70. ' Load raw data into bank 15.  Note the use of the Start function again. 
  71. ' This is because we are loading in raw data which has no special ABK  
  72. ' header information.
  73.  
  74. Bload F$,Start(15)
  75.  
  76. ' Unsquash the raw data and store size of unsquashed data in L.
  77.  
  78. L= Extension_5_00E4(Start(15),SIZEOFFILE)
  79.  
  80. ' Shrink the size of bank 15 to the size of the uncompressed data so 
  81. ' we don't waste memory. 
  82.  
  83. Bank Shrink 15 To L
  84.  
  85. ' Redisplay the picture!   
  86.  
  87. Unpack 15 To 0
  88. Screen To Front 1
  89.  
  90. Screen 1 : Print "Saved ";L-SIZEOFFILE;" bytes!"